home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD-ROM Today - The Disc! 5
/
CD-ROM Today - The Disc (Issue 5)(November 1994).ISO
/
mac
/
Mac shareware
/
Education
/
RLaB
/
help
/
FOR
< prev
next >
Wrap
Text File
|
1994-09-21
|
1KB
|
50 lines
FOR:
The RLaB for statement is NOT similar to the C for statement.
The correct usage is best shown by example...
Example:
> for(i in 1:4) {
> for(j in 1:5) {
> m[i;j] = i+j;
> }
> }
The above shows a nested set of for statements. i and j are
automatically initialized to have the values of the vector
expressions `1:4' and `1:5'. Each loop proceeds until i and j
have been assigned each element of their respective vector
expressions.
The vector in the for statement can be any expression that
evaluates to a SCALAR or a MATRIX. If the expression evaluates
to a SCALAR the body of the for statement is executed ONCE. If
the expression evaluates to an empty-matrix ( `[]' ), then the
loop is not executed at all.
The for statement can be also be used to loop through the
elements of a LIST.
Example:
> xlist = << Mass = sqrt(200); Inertia = eye(3,3); xdot = [1,2,3] >>
Inertia Mass xdot
> for( i in members(xlist) )
{
xlist.[i]
}
Inertia =
matrix columns 1 thru 3
1 0 0
0 1 0
0 0 1
Mass =
14.14
xdot =
matrix columns 1 thru 3
1 2 3
See Also: VECTOR